#ifndef QCONNECTIONWIDGET_H
#define QCONNECTIONWIDGET_H

#include <QWidget>
#include <QRadioButton>
#include <QButtonGroup>
#include <QGroupBox>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QLineEdit>
#include <QLabel>
#include <QSpinBox>
#include <QPushButton>
#include <QComboBox>

#include "qdataconnection.h"

class QConnectionWidget : public QWidget
{
  Q_OBJECT
public:
  QConnectionWidget(QWidget *parent = 0);

signals:
  void dataIn(QByteArray);
  void connectionChanged(bool);
public slots:
  void dataOut(QByteArray);

private:

  // GUI OBJECTS
  // Source
  QGroupBox *sourceBox;
  QVBoxLayout *sourceLayout;
  QButtonGroup *sourceGroup;
  QRadioButton *tcpButton;
  QRadioButton *udpButton;
  QRadioButton *serialButton;

  // Settings
  QVBoxLayout *setbtnLayout;
  QGridLayout *settingsLayout;
  QHBoxLayout *port_baudLayout;
  QLabel *addr_portLabel;
  QLabel *port_baudLabel;
  QLineEdit *addr_portEdit;
  QSpinBox *portSpin;
  QComboBox *baudCombo;

  // Buttons
  QPushButton *connectButton;

  // Main
  QHBoxLayout *mainLayout;

  // DATA CONNECTION
  QDataConnection *dataConn;

  // Variables
  bool connected;

  // Functions
  void init();

private slots:
  void toggleSource(int);
  void incomingData(connectionInfo, QByteArray);
  void toggleConnection(bool);
  void serverDisconnect();
  void serverConnect();
};

#endif // QCONNECTIONWIDGET_H
